package com.mud.mudcommune.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.mud.mudcommune.R;
import com.mud.mudcommune.entry.ArticleEntry;
import com.mud.mudcommune.entry.ArticleResponse;

import java.util.List;

import butterknife.ButterKnife;

import static com.mud.mudcommune.R.id.article;

/**
 * Created by Administrator on 2017/2/19 0019.
 */

public class ArticleAdapter extends MyBaseAdapter {
    private Context context;
    private List list;

    public ArticleAdapter(Context context, List list) {
        super(list);
        this.context = context;
        this.list = list;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ArticleEntry articleEntry = (ArticleEntry) list.get(position);
        ArticleAdapter.ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.strategy_homepager, null);
            viewHolder = new ArticleAdapter.ViewHolder(view);
        } else {
            viewHolder = (ArticleAdapter.ViewHolder) view.getTag();
        }
        if (articleEntry != null) {
            Glide.with(context)
                    .load(articleEntry.getArticleImg())
                    .into(viewHolder.background);
        }
        viewHolder.desc.setText(articleEntry.getDescription());
        viewHolder.title.setText(articleEntry.getTitle());
        viewHolder.name.setText(articleEntry.getUserName());
        return view;
    }

    static class ViewHolder {
        ImageView background;
        TextView eye_num;
        TextView star_num;
        TextView name, desc, title;

        public ViewHolder(View view) {
            background = ButterKnife.findById(view, R.id.background);
            eye_num = ButterKnife.findById(view, R.id.eye_num);
            star_num = ButterKnife.findById(view, R.id.star_num);
            desc = ButterKnife.findById(view, R.id.desc);
            title = ButterKnife.findById(view, R.id.title);
            name = ButterKnife.findById(view, R.id.name);
            view.setTag(this);
    }}
}